package com.hunan.yllxy.repostitory.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hunan.yllxy.repostitory.entity.UserDakaInfo;
import com.hunan.yllxy.repostitory.mapper.UserDakaInfoMapper;
import com.hunan.yllxy.repostitory.dao.UserDakaInfoDao;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hunan.yllxy.util.DateUtils;
import com.hunan.yllxy.util.PageResultUtils;
import com.hunan.yllxy.vo.PageQuery;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 刘华
 * @since 2025-06-20
 */
@Service
public class UserDakaInfoDaoImpl extends ServiceImpl<UserDakaInfoMapper, UserDakaInfo> implements UserDakaInfoDao {
    @Override
    public UserDakaInfo findByContentId(String userId, String dakaContentId) {
        return baseMapper.findByContentId(userId, dakaContentId);
    }

    @Override
    public List<UserDakaInfo> findByContentIdList(String userId, String dakaContentId) {
        return baseMapper.findByContentIdList(userId,dakaContentId);
    }

    @Override
    public List<UserDakaInfo> findByActivityIdAndDate(String userId, String activityId, Date date) {
        LambdaQueryWrapper<UserDakaInfo> query = Wrappers.lambdaQuery(this.entityClass);
        query.eq(UserDakaInfo::getUserId, userId);
        query.eq(UserDakaInfo::getActivityId, activityId);
        Date firstDay = DateUtils.firstDay(date);
        Date lastDay = DateUtils.lastDay(date);
        query.between(UserDakaInfo::getUpdateTime,firstDay,lastDay);

        return baseMapper.selectList(query);
    }

    @Override
    public Page<UserDakaInfo> queryUserRecord(PageQuery pageQuery, String userId, String activityId, String dakaContentId, String dakaOptionId) {
        Page page = PageResultUtils.getPage(pageQuery, this.entityClass);

        return baseMapper.queryUserRecord(page,userId,activityId,dakaContentId,dakaOptionId);
    }

    @Override
    public List<UserDakaInfo> queryUserRecordList(String userId, String activityId, String dakaContentId, String dakaOptionId) {

        return baseMapper.queryUserRecordList(userId,activityId,dakaContentId,dakaOptionId);
    }
}
